/**
 * Created by meiguizhinian on 2018/7/19
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

//cocos2dx class
ivy.UICheckBoxGroup = ivy.UIAniBox.extend({
	ctor: function (formName, blockName, sourceControlData) {
		this._super();
		this._childCheckBoxBlockNamesMap = new LLDictionary();
		if (formName && blockName && sourceControlData) {
			this.initWith(formName, blockName, sourceControlData);
		}
	},
	initWith : function(formName, blockName, sourceControlData) {
		this._super(formName, blockName, sourceControlData);
		let uim = ivy.UIManager.getInstance();
		let blockNamesStr = uim.getControlStringDataByFindIndex(sourceControlData.propertyDataFindIndex[ivy.DefaultSourceControlTypes.SCT_ELEMENT_AniCheckBoxGroup_CheckBoxBlockNames_string]);
		let names = blockNamesStr.split("|");
		for (let i=0; i!==names.length; ++i) {
			this._childCheckBoxBlockNamesMap.set(names[i], i);
		}
		ivy.Tools.pushFunctionToCocosThread(function() {
			let checkBoxesVec = [];//std::vector<UIBase*>
			for (let child of this._childrenList) {
				if (this._childCheckBoxBlockNamesMap.has(child.getBlockName()) && child instanceof ivy.UICheckBox) {
					checkBoxesVec.push(child);
				}
			}
			for (let checkBox of checkBoxesVec) {
				checkBox.setCheckBoxType(ivy.UICheckBox.UICheckBoxType.eOwnedByGroup);
				checkBox.onCheckChanged().add(function(sender) {
					for (let checkBox of checkBoxesVec) {
						checkBox.setCheckedWithoutChangeCallFunc(checkBox === sender);
					}
				});
			}
		}.bind(this));
		this.setUIElementName(formName, blockName);
	},
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////protected:
	getChildCheckBoxBlockNamesMap : function() {
		return this._childCheckBoxBlockNamesMap;
	},
	_childCheckBoxBlockNamesMap : null,//std::map<std::string, int32_t>
});

ivy.UICheckBoxGroup.create = function (formName, blockName, sourceControlData) {
	return new ivy.UICheckBoxGroup(formName, blockName, sourceControlData);
};
